home *** CD-ROM | disk | FTP | other *** search
- Path: news.ucdavis.edu!usenet
- From: ez055808@peseta.ucdavis.edu (Bill Clark)
- Newsgroups: comp.lang.c++
- Subject: Problem w/ VC 4.1 and the Deadly Diamond
- Date: 21 Mar 1996 04:38:37 GMT
- Organization: Huh?
- Message-ID: <4iqmgd$fuk@mark.ucdavis.edu>
- NNTP-Posting-Host: reqf-090.ucdavis.edu
- Mime-Version: 1.0
- Content-Type: Text/Plain; charset=US-ASCII
- X-Newsreader: WinVN 0.99.7
-
- The following code doesn't compile under VC 4.1 (or 4.0) (I haven't tried it
- yet with other compilers):
-
- ---------------------------------------------------------------
- class A
- {
- public:
- A() { }
- virtual ~A() { }
- };
-
- class B: virtual public A
- {
- public:
- B();
- virtual ~B() { }
- };
-
- B::B(): A()
- {
- }
-
- class C: virtual public A
- {
- public:
- C();
- virtual ~C() { }
- };
-
- C::C(): A()
- {
- }
-
- class D: public B, public C
- {
- public:
- D();
- virtual ~D() { }
- };
-
- D::D(): B(), C()
- {
- }
-
-
- class TestClass: public D
- {
- public:
- TestClass();
- virtual ~TestClass() { }
- };
-
- TestClass::TestClass(): D()
- {
- }
-
-
- void
- testFunc1(const TestClass t)
- {
- }
-
- void
- testFunc2()
- {
- TestClass t;
- testFunc1(t);
- }
-
- void
- main(void)
- {
- testFunc2();
- }
-
- ------------------------------------------------------------------
- The call to testFunc1() gives the following error message:
-
- error C2662: '__vbaseDtor' : cannot convert 'this' pointer from 'const class
- TestClass *' to 'class TestClass *const '
-
- If I change the parameter in testFunc1() to a ref, i.e. const TestClass& t,
- then it compiles fine.
-
- Of course, it should be passed by reference; but I don't understand why I'm
- getting this error. If I un-virtual the inheritance of B and C from A (thus
- avoiding the deadly diamond, but causing other headaches), then no compiler
- error.
-
- What gives???
-
- Thanks,
- Bill Clark
-
-